package com.project.frba.bi.queueing.mappers;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.jdbc.core.RowMapper;

import com.project.frba.bi.extraction.database.ExtractionRow;

public class ExtractionRowMapper implements RowMapper {

	@Override
	public Object mapRow(ResultSet rs, int index) throws SQLException {
		long metric = rs.getLong(1);
		ExtractionRow row = new ExtractionRow();
		row.addPropertyValue("metric", metric);
		Integer columnCount = rs.getMetaData().getColumnCount();
		
		for (int i = 2; i <= columnCount; i++) {
			String propertyName = rs.getMetaData().getColumnLabel(i);
			Object value = rs.getObject(i);
			row.addPropertyValue(propertyName, value);
		}
		
		return row;
	}
}
